package biznussoft.metercor.fragments;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import biznussoft.metercor.R;
import biznussoft.metercor.entity.AccountModel;
import biznussoft.metercor.entity.ContactsModel;
import biznussoft.metercor.utils.ExpandCollapseAnimation;


public class ContactsFragment  extends Fragment{



	AccountModel model;

	ArrayList<ContactsModel> list;
	private int mHeight = 0;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.recentupdates,container, false);
	}

	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);


	}


	public  void displayEmployeeDetails(int position){

		try{
		model = AccountsFragment.list.get(position);
		list = AccountsFragment.subContactsList.get(model.getId());

		LinearLayout mainLayout = (LinearLayout) getView().findViewById(R.id.sectionsLayout);
		for (int i = 0; i < list.size(); i++) {

			ContactsModel donor = list.get(i);
			View view = getActivity().getLayoutInflater().inflate(R.layout.displaydetails, mainLayout,false);

			//View headerColor = (View)view.findViewById(R.id.title_graphic);
			//headerColor.setBackgroundResource(R.drawable.title_bar_orange);

			TextView	mName = (TextView) view.findViewById(R.id.tvContactLastName);
			TextView	mBgroup = (TextView) view.findViewById(R.id.tvContactTitle);
			TextView 	mAge = (TextView) view.findViewById(R.id.tvContactEmail);
			TextView 	mGender = (TextView) view.findViewById(R.id.tvContactPhone);

			mName.setText(donor.getLastName());
			mBgroup.setText(donor.getTitle());
			mAge.setText(donor.getEmail());
			mGender.setText(donor.getPhone());

			mainLayout.addView(view);


			final ImageView iv_expandcollapse = (ImageView) view.findViewById(R.id.iv_CollapseExpand);
			final LinearLayout sectionitemsParent = (LinearLayout) view.findViewById(R.id.llSectionItems);
			iv_expandcollapse.setImageResource(R.drawable.expand);
			sectionitemsParent.setVisibility(View.GONE);


			iv_expandcollapse.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {

					if (sectionitemsParent.getVisibility() == View.VISIBLE) {// Collapse
						ExpandCollapseAnimation collapseAnimation = new ExpandCollapseAnimation(sectionitemsParent, 1000, 1, iv_expandcollapse);
						mHeight = collapseAnimation.getHeight();
						iv_expandcollapse.startAnimation(collapseAnimation);
					} else {// Expand
						ExpandCollapseAnimation expandAnimation = new ExpandCollapseAnimation(sectionitemsParent, 1000, 0, iv_expandcollapse);
						if (mHeight == 0) {
							mHeight = getSectionitemsHeight();
						}
						expandAnimation.setHeight(mHeight);
						iv_expandcollapse.startAnimation(expandAnimation);
					}
				}

				private int getSectionitemsHeight() {
					return (int) (4 * getResources().getDimension(R.dimen.section_item_height));
				}
			});
		}
		}catch(Exception ex){
			
		}
	}
	public static View getDividerView(Context context) {
		View dividerView = new View(context);
		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 2);
		dividerView.setLayoutParams(lp);
		dividerView.setBackgroundResource(android.R.drawable.divider_horizontal_bright);
		return dividerView;
	}



}